<CFSETTING ENABLECFOUTPUTONLY="Yes">

<CFSET lHasRecord=false>
<!--- get the employee --->
<CFQUERY NAME="GetEmployee" DATASOURCE="#client.company_dsn#" MAXROWS=1>
  SELECT PERSONNELIDNO, LASTNAME, FIRSTNAME
	FROM CMFPA
	WHERE	(GUID = '#client.guid#')
</CFQUERY>

<!--- There should be record to view --->
<CFIF GetEmployee.RecordCount>
	<CFSET sTypeID = url.id>

	<!--- check if user has access to the form --->
	<CFSET sRightID = "">
	<CFINCLUDE TEMPLATE="../common/_validate.cfm">

	<CFIF sRightID NEQ "">
		<!--- get for form details --->
		<CFQUERY NAME="GetForm" DATASOURCE="#client.company_dsn#">
			SELECT DISTINCT
		<!--- E.*, --->
		E.FORMCODE, E.FORMGROUP, E.FORMTYPE, E.DESCRIPTION, E.TABLENAME_FK,E.ENABLEBATCHAPPLY
		E.PK_FIELD1, E.PK_FIELD2, E.PK_FIELD3, E.PK_FIELD4, E.PK_FIELD5,
		E.TEMPLATECODE_FK, E.ICONNAME, E.PROCESSCODE, E.RECORDFILTER,
		E.CALENDARFIELD, E.MASTERDETAIL, E.PREPROCESS, E.PREPROCESSTITLE,E.ATTACHEDLINK,
			 	E1.ISADD, E1.ISEDIT, E1.ISDELETE, E1.ISVIEW, E1.ISEMAIL, E1.ISPRINT,E1.BATCHAPPLY
			FROM ECRGFORMS E, ECRTFORMS E1
			WHERE
				(E1.USERGRPID_FK IN (#preserveSingleQuotes(sRightID)#)) AND
				(E1.FORMCODE_FK  = E.FORMCODE) AND
				(E1.FORMCODE_FK  = '#sTypeID#')
		</CFQUERY>

		<CFSET accessAdd = 'N'>
		<CFSET accessEdit = 'N'>
		<CFSET accessDelete = 'N'>
		<CFSET accessView = 'N'>
		<CFSET accessEmail = 'N'>
		<CFSET accessPrint = 'N'>
		<CFSET accessBatchApp = 'N'>

		<CFLOOP QUERY="GetForm">
			<CFIF GetForm.ISADD EQ 'Y'>
				<CFSET accessAdd = 'Y'>
			</CFIF>
			<CFIF GetForm.ISEDIT EQ 'Y'>
				<CFSET accessEdit = 'Y'>
			</CFIF>
			<CFIF GetForm.ISDELETE EQ 'Y'>
				<CFSET accessDelete = 'Y'>
			</CFIF>
			<CFIF GetForm.ISVIEW EQ 'Y'>
				<CFSET accessView = 'Y'>
			</CFIF>
			<CFIF GetForm.ISEMAIL EQ 'Y'>
				<CFSET accessEmail = 'Y'>
			</CFIF>
			<CFIF GetForm.ISPRINT EQ 'Y'>
				<CFSET accessPrint = 'Y'>
			</CFIF>
			<CFIF GetForm.BATCHAPPLY EQ 'Y'>
				<CFSET accessBatchApp = 'Y'>
			</CFIF>
		</CFLOOP>


		<!--- Get the form properties --->
		<CFIF GetForm.RecordCount>
			<CFQUERY NAME="GetLevelID" DATASOURCE="#client.global_dsn#">
				SELECT LEVELID
				FROM GRGBOSETABLE
				WHERE TABLENAME = '#GetForm.TABLENAME_FK#'
			</CFQUERY>

			<!--- Must be defined in data-dictionary --->
			<CFIF GetLevelID.RecordCount>
				<!--- get table location --->
				<!--- custom tag: parameter: DBLEVEL; return value: DSN --->
				<CFMODULE TEMPLATE="#client.common_path#cfm_leveldsn.cfm" DBLEVEL="#GetLevelID.LEVELID#">
				<CFSET table_dsn = DSN>
				<CFSET sFields   = "">

				<!--- get the fields for the form --->
				<CFQUERY NAME="GetFields" DATASOURCE="#client.global_dsn#">
					SELECT *
					FROM GRGBOSETABLEFIELDS
					WHERE
						(TABLENAME  = '#GetForm.TABLENAME_FK#') AND
						(ISVISIBLEEFORM    = 'Y' OR ISVISIBLEEFORM IS NULL) AND
						(COLUMNNAME <> 'PERSONNELIDNO') AND
						(COLUMNNAME <> 'RECDATECREATED') AND
						(COLUMNNAME <> 'RECCREATEDBY') AND
						(COLUMNNAME <> 'USERID') AND
						(COLUMNNAME <> 'DATELASTUPDATE') AND
						(COLUMNNAME <> 'TIMELASTUPDATE') AND
						(COLUMNNAME <> 'ROUTEID') AND
						(COLUMNNAME <> 'APPROVED') AND
						(#sqlSTRLEN#(COLUMNDESC) > 0)
					ORDER BY FIELDGROUP, COLUMNORDER, COLUMNDESC, COLUMNNAME
				</CFQUERY>

				<CFOUTPUT QUERY="GetFields">
					<CFSET sFields = sFields & "#COLUMNNAME#,">
				</CFOUTPUT>

				<!--- Fields in data-dict must be defined --->
				<CFIF GetFields.RecordCount>
					<CFQUERY NAME="GetEntry" DATASOURCE="#table_dsn#" MAXROWS=1>
			     		SELECT *
						FROM #GetForm.TABLENAME_FK#
						WHERE
							(PERSONNELIDNO = '#GetEmployee.PERSONNELIDNO#')
							<CFLOOP  INDEX="x" FROM="1" TO="5">
								<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "">
									<CFSET theVal = evaluate("url." & evaluate("GetForm.PK_FIELD" & x))>
									AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
								</CFIF>
							</CFLOOP>
				   	</CFQUERY>

					<!--- get the details to display --->
					<CFIF GetEntry.RecordCount>
						<CFSET lHasRecord=true>
					</CFIF> <!--- get the details to display --->
				</CFIF> <!--- Fields in data-dict must be defined --->
			</CFIF> <!--- Must be defined in data-dictionary --->
		</CFIF> <!--- Get the form properties --->
	</CFIF> <!--- check if user has access to the form --->
</CFIF> <!--- There should be record to view --->

<CFSETTING ENABLECFOUTPUTONLY="No">

<html>
<head>
	<title>iBOS/e eForms</title>
	<script>
	function TransferValue(lstFields) {
	var aTemp=lstFields.split(","), nCnt
		for (nCnt=0; nCnt < aTemp.length; nCnt++) {
			if (nCnt == 0)
				eval("window.opener.document.frmDetails." + aTemp[nCnt]).focus()
			eval("window.opener.document.frmDetails." + aTemp[nCnt]).value=eval("document.frmContainer." + aTemp[nCnt]).value
		}
	}
	</script>
</head>
<body>
	<CFIF lHasRecord>
		<CFSET lstFields="">
		<CFSET sComma="">
		<form name="frmContainer" METHOD="POST">
			<CFOUTPUT QUERY="GetFields" GROUP="FIELDGROUP">
				<CFIF len(trim(FIELDGROUP)) NEQ 0>
					<!--- Do nothing in grouping separator --->
				</CFIF>

				<CFOUTPUT>
					<!--- get the value of the entry --->
					<CFSET sEntryValue = #evaluate("GetEntry." & COLUMNNAME)#>
					<CFIF lcase(COLUMNTYPE) IS "ftdatetime">
						<CFSET sEntryValue = DateFormat(sEntryValue, "mmm dd, yyyy")>
					</CFIF>

					<CFSET lstFields=lstFields & sComma & "#COLUMNNAME#">
					<CFSET sComma=",">

					<!--- get the description in the lookup --->
					<CFQUERY NAME="GetLookup" DATASOURCE="#client.global_dsn#">
							SELECT A.*, B.LEVELID
							FROM GSTLOOKUP A, GRGBOSETABLE B
							WHERE (A.MASTERTABLE = '#GetForm.TABLENAME_FK#') AND
								  (A.MASTERFIELD = '#COLUMNNAME#') AND
								  (A.LOOKUPTABLE = B.TABLENAME)
					</CFQUERY>

					<CFIF GetLookup.RecordCount AND len(trim(sEntryValue)) NEQ 0>
						<CFSET sLkValue = "">
						<CFIF trim(GetLookup.LEVELID) NEQ "" AND
							  trim(GetLookup.LOOKUPKEYFIELD) NEQ "" AND
							  trim(GetLookup.LOOKUPRESULTFIELD) NEQ "" AND
							  trim(GetLookup.LOOKUPTABLE) NEQ "">
							<!--- get table location --->
							<!--- custom tag: parameter: DBLEVEL; return value: DSN --->
							<CFMODULE TEMPLATE="#client.common_path#cfm_leveldsn.cfm" DBLEVEL="#GetLookup.LEVELID#">
							<CFSET lk_dsn = DSN>

							<CFQUERY NAME="GetLkDesc" DATASOURCE="#lk_dsn#">
								SELECT #GetLookup.LOOKUPRESULTFIELD#
								<!--- For extra lookup description --->
								<CFIF Trim(GetLookup.EXTRARESULTFLD) NEQ "">
									,#GetLookup.EXTRARESULTFLD#
								</CFIF>
								FROM #GetLookup.LOOKUPTABLE#
								WHERE
									(#GetLookup.LOOKUPKEYFIELD# = '#sEntryValue#')
							</CFQUERY>

							<CFIF GetLkDesc.RecordCount>
								<CFIF LCase(ISORGCHART) IS "y">
									<CFSET lstFields=lstFields & sComma & "hid#COLUMNNAME#">
									<input type="hidden" name="hid#COLUMNNAME#" value="#sEntryValue#">
								</CFIF>


								<CFSET sEntryValue=sEntryValue & " - #evaluate('GetLkDesc.' & GetLookup.LOOKUPRESULTFIELD)#">
								<!--- For extra lookup description --->
								<CFLOOP LIST="#GetLookup.EXTRARESULTFLD#" INDEX="x">
									<CFSET x = trim(x)>
									<!--- get datatype for extra result field --->
									<CFIF NOT ListFind(sFields,#x#)>

										<CFQUERY NAME="GetDataType" DATASOURCE=#client.global_dsn#>
											SELECT COLUMNTYPE
											FROM GRGBOSETABLEFIELDS
											WHERE (TABLENAME = '#Trim(GetLookup.LOOKUPTABLE)#') AND
											 	  (COLUMNNAME = '#x#')
										</CFQUERY>

										<CFSET sExtraDesc=#evaluate("GetLkDesc." & Trim(x))#>
										<CFIF LCase(GetDataType.COLUMNTYPE) IS "ftdatetime">
											<CFSET sExtraDesc=DateFormat(sExtraDesc, "mmmm d, yyyy")>
										</CFIF>
											<input type="hidden" name="#x#" value="#HTMLEditFormat(sExtraDesc)#">
										<CFSET lstFields=lstFields & sComma & "#x#">
									</CFIF>
								</CFLOOP>
							<CFELSE>
								<CFSET sEntryValue=sEntryValue & " - [value not found in the lookup.]">
							</CFIF>
						</CFIF>
					</CFIF>

					<input type="hidden" name="#COLUMNNAME#" value="#HTMLEditFormat(sEntryValue)#">
				</CFOUTPUT>
			</CFOUTPUT>
		</form>
	</CFIF>

	<CFOUTPUT>
	<script>
		<CFIF lHasRecord>
			TransferValue('#lstFields#')
		</CFIF>
	</script>
	</CFOUTPUT>
</body>
</html>